package com.tcm.common.handler;

import com.tcm.common.InputStreamHttpServletRequestWrapper;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 对所有请求进行过滤，将所有request请求转变为InputStreamHttpServletRequestWrapper增强request类，
 * 便于日志中接口参数获取
 */
public class HttpServletRequestInputStreamFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        // 转换为可以多次获取流的request
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        // 放行
        filterChain.doFilter(new InputStreamHttpServletRequestWrapper(httpServletRequest), servletResponse);
    }
}
